package com.wjj.happytime.fragment.main_frg;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wjj.happytime.R;
import com.wjj.happytime.adapter.happy_frg_adapter.HappyFrgViewPagerAdapter;
import com.wjj.happytime.entity.happy_entity.TypeEntity;

import java.util.LinkedList;

/**
 * A simple {@link Fragment} subclass.
 */
public class HappyFragment extends Fragment {


    private TabLayout tabLayout;
    private ViewPager viewPager;
    private HappyFrgViewPagerAdapter adapter;
    private LinkedList<TypeEntity> tabs;

    public HappyFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_happy, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        //初始化控件
        initView(view);
        //准备标签数组
        tabs = new LinkedList<>();
        tabs.add(new TypeEntity("精华","day"));
        tabs.add(new TypeEntity("视频","video"));
        tabs.add(new TypeEntity("纯文","text"));
        tabs.add(new TypeEntity("纯图","imgrank"));

        //适配器
        adapter = new HappyFrgViewPagerAdapter(getFragmentManager(),tabs);
        //绑定适配器
        viewPager.setAdapter(adapter);
        //tabLayout和viewPager关联
        tabLayout.setupWithViewPager(viewPager);

    }

    //初始化控件
    private void initView(View view) {
        tabLayout = ((TabLayout) view.findViewById(R.id.tab_layout_happy_id));
        viewPager = ((ViewPager) view.findViewById(R.id.view_pager_happy_id));
    }


}
